package com.wetsoft.base.test01

//大师
class Master
//专家
class Professor extends Master

//讲师
class Teacher04 extends Master

//这个是协变，Professor是Master的子类，此时Card[Professor]也会是Card[Master]的子类
//class Card[+T]
//这个是逆变，只能是Card02[T]及其Card02[T]子类
class Card[-T]


class CovariantDemo{
  //只有Card[Master]及其子类Card[Professor]，才能进入会场！
//  def enterMeet(card: Card[Master]): Unit = {
//    println("只有大师及其下一级别的人，才能进入会场！")
//  }

  def enterMeet(card: Card[Teacher04]): Unit = {
    println("只有大师及其下一级别的人，才能进入会场！")
  }
}

object CovariantDemo {

  def main(args: Array[String]): Unit = {
    val masterCard = new Card[Master]

    val professorCard = new Card[Professor]

    var teacher04Card = new Card[Teacher04]

    val covariant = new CovariantDemo()


    covariant.enterMeet(masterCard)

//    covariant.enterMeet(professorCard)

    covariant.enterMeet(teacher04Card)

  }

}
